package com.example.robot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/recharge")
public class RobotController {

    @Autowired
    private RobotMessageService robotMessageService;

    @GetMapping("/send")
    public Map<String, Object> sendMsg() {
        return pushRechargeData();
    }

    /**
     * 推送每日流水到企微
     */
    public Map<String, Object> pushRechargeData() {

        String webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=406f7243-6a05-48a9-9aae-9d4aed0060dd";

//        Connection conn = clickHouseUtils.connection();
//        ResultSet resultSet = null;
//        ClickHousePreparedStatement pst = null;

//            List<Object> paramList = new ArrayList<>();
//
//            String sql = "SELECT * from events_db.event_log WHERE eventType = 42 and `timestamp` BETWEEN '2023-08-21 00:00:00' and '2023-08-21 23:59:59';\n";
//            sql = sqlUtils.boundCommonCondition(sql, paramList, activityLogQuery);
//            sql += " group by visitParamExtractInt(detail , 'grade'),visitParamExtractInt(detail , 'isWin')";
//            Object[] params = paramList.toArray();
//            pst = (ClickHousePreparedStatement) conn.prepareStatement(sql);
//            for (int i = 0; i < params.length; i++) {
//                pst.setObject(i + 1, params[i]);
//            }
//            resultSet = pst.executeQuery();
//            List<SummaryPKDetail> summaryPKDetails = new ArrayList<>();
//            while (resultSet.next()) {
//                SummaryPKDetail summaryPKDetail = new SummaryPKDetail();
//                int grade = resultSet.getInt("grade");
//                summaryPKDetail.setGrade(grade);
//                Integer isWin = resultSet.getInt("isWin");
//                summaryPKDetail.setIsWin(isWin);
//                long count = resultSet.getLong("count");
//                summaryPKDetail.setCount((int) count);
//                summaryPKDetails.add(summaryPKDetail);
//            }


        Map<String, Object> map = new HashMap<>();
        ChargeData data = new ChargeData(100, 150, System.currentTimeMillis());
        String content = data.toString();
        map.put("content", content);
        List<String> list = new ArrayList<>();
        list.add("@all");
        list.add("17732722662");
        list.add("18303617322");
        map.put("mentioned_mobile_list", list);
        robotMessageService.sendGroupMessage(webhook, map);
        return map;

    }

}
